
#include "CIOMapping.h"
#include "COutputStates.h"
#include "pugixml/src/pugixml.hpp"
#include <iostream>
#include <list>
#include <string>


using namespace std;



int main()
{

	CIOMapping *itsIOMapping = CIOMapping::getInstance();
	COutputStates *itsOutputStates = COutputStates::getInstance();

	
	if (false == itsIOMapping->init())
	{
		cout << "Error init IOMapping" << endl;
	}

	if (false == itsOutputStates->init())
	{
		cout << "Error init OutputStates" << endl;
	}
	
	
	
	while (1)
	{
	
		string ioNumber = "";

		cout << endl << "--------------------" << endl << "==> Enter io number: "; 
		cin >> ioNumber;
		
		
		cout <<  endl << "------ iomapping.xml - input " << ioNumber << " info ----------------------------------" << endl << endl;

		string inputAlias ("");
		if (true == itsIOMapping->getInputAlias(ioNumber, inputAlias))
		{
			cout << "<alias> " << inputAlias << endl;
		}
		else
		{
			cout << "<alias> error" << endl;
		}

		string location ("");
		if (true == itsIOMapping->getInputLocation(ioNumber, location))
		{
			cout << "<location> " << location << endl;
		}
		else
		{
			cout << "<location> error" << endl;
		}


		list<string> tempList;

		if (true == itsIOMapping->getInputMappedOutputs(ioNumber, tempList))
		{
			if (true == tempList.empty())
			{
				cout << "<mapping>" << endl;
			}
			else
			{			
				list<string>::iterator it;
				for (it = tempList.begin(); it != tempList.end(); it++)
				{
					cout << "<mapping> output " << *it << endl;
				}
			}
		}
		else
		{
			cout << "<mapping> output error" << endl;
		}


		cout <<  endl << "------ iomapping.xml - output " << ioNumber << " info ---------------------------------" << endl << endl;


		string outputAlias ("");
		if (true == itsIOMapping->getOutputAlias(ioNumber, outputAlias))
		{
			cout << "<alias> " << outputAlias << endl;
		}
		else
		{
			cout << "<alias> error" << endl;
		}

		string outputLocation ("");
		if (true == itsIOMapping->getOutputLocation(ioNumber, outputLocation))
		{
			cout << "<location> " << outputLocation << endl;
		}
		else
		{
			cout << "<location> error" << endl;
		}

		string outputFunction ("");
		if (true == itsIOMapping->getOutputFunction(ioNumber, outputFunction))
		{
			cout << "<function> " << outputFunction << endl;
		}
		else
		{
			cout << "<function> error" << endl;
		}


		cout <<  endl << "------ outputstates.xml - output " << ioNumber << " info ------------------------------" << endl << endl;
		
		
		
		string outputState("");
		if (true == itsOutputStates->getOutputState(ioNumber, outputState))
		{
			cout << "<state> " << outputState << endl;
		}
		else
		{
			cout << "<state> error" << endl;
		}

		string outputBrightness("");
		if (true == itsOutputStates->getOutputBrightness(ioNumber, outputBrightness))
		{
			cout << "<brightness> " << outputBrightness << endl;
		}
		else
		{
			cout << "<brightness> error" << endl;
		}
		

		cout <<  endl << "------ saved_outputstates.xml - set new data for output " << ioNumber << " ------------" << endl << endl;
		
		
		string newOutputState("");
		
		cout << endl << "----------------------" << endl << "==> Enter new <state>: "; 
		cin >> newOutputState;
		
		if (false == itsOutputStates->setOutputState(ioNumber, newOutputState))
		{
			cout << "<state> error" << endl;
		}
		
		
		string newBrightness("");
		
		cout << "---------------------------" << endl << "==> Enter new <brightness>: "; 
		cin >> newBrightness;
		
		if (false == itsOutputStates->setOutputBrightness(ioNumber, newBrightness))
		{
			cout << "<brightness> error" << endl;
		}
		
		
		if (true == itsOutputStates->saveOutputStates())
		{
			cout << endl << "successful! saving actual settings 'outputstates.xml' => 'saved_outputstates.xml'" << endl;
		}
		else
		{
			cout << endl << "error! saving actual settings 'outputstates.xml' => 'saved_outputstates.xml'" << endl;
		}

	}
	
    return 0;
}

